package 丑数;


class Solution {
    public int getUglyNumber(int n) {
        int[] arr = new int[n];
        int idx = 0;
        arr[idx] = 1;
        int i = 0, j = 0, k = 0;
        while (++idx < n) {
            int t = Math.min(arr[i] * 2, Math.min(arr[j] * 3, arr[k] * 5));
            arr[idx] = t;
            if (t == arr[i] * 2) {
                i++;
            }
            if (t == arr[j] * 3) {
                j++;
            }
            if (t == arr[k] * 5) {
                k++;
            }
        }
        return arr[n - 1];
    }
}
